package com.axjy.service.impl;

import com.axjy.mapper.UserMapper;
import com.axjy.pojo.User;
import com.axjy.service.UserService;
import com.axjy.util.Pager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * Created by asus on 2018/1/25.
 */
@Service("userService")
@Transactional
public class UserServiceImpl implements UserService{

    @Resource
    private UserMapper userMapper;
    @Override
    @Transactional(readOnly=true)
    public User login(String userCode, String userPassword) {
        User user=userMapper.find(userCode,userPassword);
        return user;
    }

    @Override
    public Pager searchPager(Integer offset) {
            Pager pager=new Pager();
            pager.setRows(userMapper.findRows(offset));
            pager.setTotal(userMapper.findTotal());
        return pager;
    }

    @Override
    public void add(User user) {
        userMapper.add(user);
    }

    @Override
    public boolean update(User user) {
        Integer result=userMapper.update(user);
        return result>0?true:false;
    }

    @Override
    public User get(Integer id) {
        return userMapper.get(id);
    }

    @Override
    public void del(Integer id) {
        userMapper.del(id);
    }

    @Override
    public boolean exists(String userCode) {
        Integer count=userMapper.exists(userCode);
        return count>0?false:true;
    }
}
